print('The quick brown fox', 'jumps over', 'the lazy dog')
#name = input('please enter your name: '):
#print('hello,',name):

print('1024 * 768 = ',1024 * 768)
a = -100
if a > 0 :
    print(a)
else:
    print(-a)

print('''line1
line2
line3''')

s4 = r'''hello,
lisa!'''

print(s4)

print(r'\t\t\t\t\t\t\t')

s1 = 72
s2 = 85
r = (s2 - s1)*100/s1
print('%0.1f%%' %r)

names = ['Michael', 'Bob', 'Tracy']
for name in names:
    print(name)

sum = 0
for x in [1, 2, 3, 4, 5]:
    sum = sum + x
print (sum)

sum = 0
for x in range(101):
    sum = sum + x
print(sum)

sum = 0
n = 99
while n > 0:
    sum = sum + n
    n = n - 2
print(sum)

L = ['Bart', 'Lisa', 'Adam']

for x in L:
    print('Hello, %s' % x)

n = 1
while n <= 100:
    if n > 10: #当n=11时，条件满足，执行Break语句
        break
    print(n)
    n += 1 # python中缩进非常重要
print('END')

n = 0
while n < 10:
    n += 1
    if n % 2 == 0:
        continue
    print(n)

#字典 dict
#类似于Map使用key-value
d = {'王天娲': 'hahahah', 'Bob' : 57}
print(d['王天娲'])

#set
s = set([1, 1, 2, 2, 3, 3])
print(s)

#str是不可变对象
a = 'abc'
b = a.replace('a','A')
print(a)
print(b)

#函数
print(max(1, 2, 3))

#数据类型转换
a = int('123')
print(a)
b = float('12.34')
print(b)

print(hex(255))

print(hex(100))




#函数

def my_abs(x):
    if x >= 0:
        return x
    else:
        return -x

print(my_abs(-1000))

#print(my_abs(1,2)) #报错

#多个返回值
import math
def move(x, y, step, angle=0):
    nx = x + step * math.cos(angle)
    ny = y - step * math.sin(angle)
    return nx, ny

x, y = move(100, 100, 60, math.pi/6)
print(x, y)

r = move(100, 100, 60, math.pi/6)
print(r) # 实际返回值为tuple

#定义类型检查
def my_abs_v2(x):
    if not isinstance(x,(int, float)):
        raise TypeError('bad operhand type')
    if x >= 0:
        return x
    else:
        return -x

print(my_abs_v2(123))

#函数位置参数


def power(x, n=2):
    s = 1
    while n > 0:
        n = n - 1
        s = s * x
    return s


print(power(10))
print(power(10,4))

def enroll(name,  gender, age = 6, city = 'Beijing'):
    print('name:', name)
    print('gender:', gender)
    print('age:', age)
    print('city:', city)


student1 = enroll('Baby', 'M',15)

def add_end(L=None):
    if L is None:
        L = []
    L.append('END')
    return L

print(add_end()) #['END']
print(add_end()) #['END', 'END']

def calc(numbers):
    sum = 0
    for n in numbers:
        sum = sum + n * n
    return sum

rtn = calc([1, 2, 3]) # list
print(rtn)

rtn = calc((1, 2, 3)) # tuple
print(rtn)

# 利用可变参数
def calc(*numbers):
    sum = 0
    for n in numbers:
        sum = sum + n * n
    return sum


rtn = calc(1, 2, 3)
print(rtn)

rtn = calc()
print(rtn)

nums = [1, 2, 3] #list
rtn = calc(*nums) #变为可变参数
print(rtn)

def person(name, age, **kw):
    print('name:', name, 'age:', age, 'other:', kw)

person("James", 30)
person("James", 30, city = 'ShenZhen')

extra = {'city': 'Beijing', 'Job': 'Engineer'}
person('Jack', 24, **extra)


def person(name, age, **kw):
    if 'city' in kw:
        pass
    if 'job' in kw:
        pass
    print('name:', name, 'age:', age, 'other:', kw)


extra = {'city': 'Beijing', 'Job': 'Engineer'}
person('Jack', 24, **extra)

def person(name, age, *, city, job):
    print(name, age, city, job)

person('Jack', 24, city='Beijing', job='Engineer')

def person(name, age, *, city='ShenZhen', job):
    print(name, age, city, job)

person('Jack', 24, job='Engineer')

def person(name, age, city, job):
    # 缺少 *，city和job被视为位置参数
    pass

def f1(a, b, c=0, *args, **kw):
    print(a, b, c, args, kw)
f1(1, 2)
# -->>1 2 0 () {}
f1(1, 2, 100)
# -->>1 2 100 () {}
f1(1, 2, 3, 'a', 'b')
# -->>1 2 3 ('a', 'b') {}
f1(1, 2, d=88)
# -->>1 2 0 () {'d': 88}

def f2(a, b, c=0, *, d, **kw):
    print(a, b, c, d, kw)

f2(1, 2, d=99, ext=None)
# 1 2 0 99 {'ext': None}


args = (1, 2, 3, 4)
kw = {'d': 99, 'x': '#'}
f1(*args, **kw)
# 1 2 3 (4,) {'d': 99, 'x': '#'}

args = (1, 2, 3)
kw = {'d': 88, 'x': '#'}
f2(*args, **kw)
# 1 2 3 88 {'x': '#'}
